#include "regsuccess_dialog.h"
#include "ui_regsuccess_dialog.h"

RegSuccess_Dialog::RegSuccess_Dialog(QWidget *parent) :counter_(5),
    QDialog(parent),
    ui(new Ui::RegSuccess_Dialog)
{
    ui->setupUi(this);
    timer_ = new QTimer(this);
    //定时器到期，更改计数，计数达到5s，发出返回登录信号
    connect(timer_,&QTimer::timeout,[this](){

        if(counter_ == 0)
        {
            timer_->stop();
            emit sig_returnLogin();
            return;
        }
        counter_--;
        QString tip = QString("注册成功，%1 s后返回登录").arg(counter_);
        ui->timer_label->setText(tip);
    });


    //返回按键按下发出返回登录信号
    connect(ui->returnLogin_btn,&QPushButton::clicked,this,[this](){
        timer_->stop();
        emit sig_returnLogin();
    });

    timer_->start(1000);
}

RegSuccess_Dialog::~RegSuccess_Dialog()
{
    delete ui;
    delete timer_;
}
